<?php
// No direct access to this file
defined('_JEXEC') or die;
 
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
 
/**
 * HelloWorld Form Field class for the HelloWorld component
 */
class JFormFieldPhongThuy extends JFormFieldList
{
        /**
         * The field type.
         *
         * @var         string
         */
        protected $type = 'PhongThuy';
 
        /**
         * Method to get a list of options for a list input.
         *
         * @return      array           An array of JHtml options.
         */
        protected function getOptions() 
        {
                $db = JFactory::getDBO();
		//		$query = new JDatabaseQuery;
				$query = $db->getQuery(true);
				$query->select('#__phongthuy.id as id,greeting,#__categories.title as category,cat_id');
				$query->from('#__phongthuy');
				$query->leftJoin('#__categories on cat_id=#__categories.id');
				$db->setQuery((string)$query);
				$messages = $db->loadObjectList();
				$options = array();
				if ($messages)
				{
					foreach($messages as $message) 
					{
						$options[] = JHtml::_('select.option', $message->id, $message->greeting . ($message->cat_id ? ' (' . $message->category . ')' : ''));
					}
				}
				$options = array_merge(parent::getOptions(), $options);
				return $options;
        }
}